<template>
  <div>
      <TopBar>提现</TopBar>
      <UserInfo  style="margin-top:1.5rem" @getMoney="getBackMoney" @getType="getType"></UserInfo>
      <CheckUser @passCode="getCode"></CheckUser>
      <div id="getCash">
        到账金额：<span>{{this.inputMoney}}元</span>
      </div>
      <div id="sumbitCash" @click="submit">提现</div>
      <div v-transfer-dom >
        <x-dialog :show="showHintBox" class="dialogBox" hide-on-blur>
          <Cashint @close="closeDialog"></Cashint>
        </x-dialog>
      </div>
      <toast 
        v-model="showPositionValue" 
        type="text" 
        :time="2000" 
        is-show-mask 
        :text="msg" 
        position="middle"></toast>
  </div>
</template>
<script>
import TopBar from '../../component/common/TopBar'
import UserInfo from '../getMoneyBack/children/UserInfo'
import CheckUser from '../getMoneyBack/children/CheckUser'
import Cashint from '../getMoneyBack/children/Cashint'
import { XDialog, TransferDomDirective as TransferDom } from 'vux'
import {getStore, showMsg,verify} from '../../../config/mUtils'
import {getCode,getBindInfo,getMoney} from '../../../service/getData'
import { Toast } from 'vux'
import {getSDK} from '../../../service/wxShare.js'

let time = null
export default {
  components:{
    TopBar,
    UserInfo,
    CheckUser,
    XDialog,
    Cashint,
    Toast
  },
  beforeCreate(){
    getSDK()
  },
  data(){
    return {
      cash:'0.00',
      accout:{},
      showHintBox:false,
      getMoney:0,
      phone:getStore('loginkey'),
      inputMoney:'',
      type:'',
      code:'',
      msg:'',
      showPositionValue:false,
    }
  },
  methods:{
    getType(data){
      this.type = data
    },
    getCode(data){
      this.code = data
    },
    getBackMoney(data){
      this.inputMoney = data
    },
    submit(){
      // //console.log(`${getStore('loginkey')}/${this.code}/${this.inputMoney}/${this.type}`)
      if(this.inputMoney == ''){
        console.log(this.inputMoney);
        showMsg('请输入金额',this)
      }else if(this.code == ''){
        showMsg('请输入短信验证码',this)
      }else if(!verify(this.code,3)){
        showMsg("短信验证码错误",this)
      }else{
        getMoney(getStore('loginkey'),this.code,this.inputMoney,this.type)
          .then(res=>{
            // //console.log(res)
            if(res.status == 1){
              time = setTimeout(()=>{
                this.$router.replace('/my')
              },2000)
              // this.showHintBox = true
              // location.reload();
            }
            showMsg(res.msg,this)
          })
      }
    },
    closeDialog(data){
      this.showHintBox = data
      this.$router.replace('/my')
    }
  },
  directives: {
    TransferDom
  },
  beforeDestroy(){
    clearTimeout(time)
  }
}
</script>
<style lang="less">
  @import '../../../style/mixin.less';

  #getCash{
    width: 90%;
    margin: 0 auto;
    margin-top: .2rem;
  }
  #sumbitCash{
    .wh(90%,1.2rem);
    .sc(.4rem,#fff);
    .bg(#e2472d);
    .borderRadius(2rem);
    margin: 0 auto;
    margin-top: .5rem;
    line-height: 1.2rem;
    text-align: center;
  }
  .weui-toast,.weui-toast_text,.vux-toast-middle{
        width: 70% !important;
      }
</style>
